let fs = require('fs'),
    path = require('path');

function walk(currentDirPath, config, callback) {
    fs.readdir(currentDirPath, function (err, files) {
        if (err) {
            throw new Error(err);
        }
        files.forEach(function (name) {
            let filePath = path.join(currentDirPath, name);
            let stat = fs.statSync(filePath);
            if (stat.isFile()) {
                callback(filePath,name);
            } else if (stat.isDirectory()) {
                if (config.ignoreDir.indexOf(name) === -1) {
                    walk(filePath, config, callback);
                }
            }
        });
    });
}

/**
 * 判断文件是指定格式的某一种
 */
function endWith(name, suffixs) {
    let temp = name.split(".")
    let suffix = "." + temp[temp.length - 1]
    return suffixs.indexOf(suffix) > -1
}


module.exports = {
    /**
     * 输出红色日志
     * @param msg
     */
    logError: function (msg) {
        console.log('\x1B[31m%s\x1B[0m', msg)
    },

    logWarn: function (msg) {
        console.log('\x1B[33m%s\x1B[0m', msg)
    },

    walk: walk,
    endWith:endWith
}


